package com.swadar.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.swadar.beans.dataobject.BrandDO;
import com.swadar.beans.valueobject.ProductVO;
import com.swadar.beans.valueobject.UserVO;
import com.swadar.helper.HomePageHelper;

@Controller
public class HomePageController {

	@Autowired
	private HomePageHelper helper;	
	
	@RequestMapping(value="/home.do")
	public String showProductPage(ModelMap modelMap) {
		List<ProductVO> productVOList = helper.getProductVOList(false);
		List<ProductVO> productBarwareVOList = helper.getProductVOList(true);
		List<BrandDO> imageList = helper.getBrandImage();
		if(productVOList!=null && productVOList.size()>8){
			productVOList = productVOList.subList(0, 8);
		}
		if(productBarwareVOList!=null && productBarwareVOList.size()>4){
			productBarwareVOList = productBarwareVOList.subList(0, 4);
		}
		modelMap.put("productVOList", productVOList);
		modelMap.put("productBarwareVOList", productBarwareVOList);
		modelMap.put("imageList", imageList);
		return "home";
	}
	
	
	@RequestMapping("/login.do")
	public String isValidUser(UserVO userVo){
		Integer count = helper.isValidUser(userVo);
		if(count==1){
			return "home";
		}
		return null;
	}
	
}
